<template>
  <section id="hero">
    <h1 class="tagline">
      <span class="accent">Electron-Egg</span>
    </h1>
    <el-upload
      accept=".xlsx,.xls"
      v-model:file-list="fileList"
      class="upload-demo"
      :limit="1"
      :on-change="handleFileChange"
    >
      <el-button type="primary">Click to upload</el-button>
    </el-upload>
    <el-input v-model="pathStr" />
    <el-table :data="tableData" style="width: 100%; height: 300px">
      <el-table-column prop="name" label="Name" width="180" />
      <el-table-column prop="week1" label="Week1" width="180" />
      <el-table-column prop="week2" label="Week2" />
      <el-table-column prop="week3" label="Week3" />
      <el-table-column prop="week4" label="Week4" />
    </el-table>
    <p class="actions">
      <a class="setup" :onclick="test111">Get Started</a>
    </p>
  </section>
</template>
<script>
import { ipc } from "../../../utils/ipcRenderer";
import {
  ElInput,
  ElTable,
  ElTableColumn,
  ElUpload,
  ElButton,
} from "element-plus";

export default {
  components: {
    ElInput,
    ElTable,
    ElTableColumn,
    ElUpload,
    ElButton,
  },
  data() {
    return {
      test: "",
      pathStr: "",
      excelResult: "",
      tableData: [],
      fileList: [],
    };
  },
  methods: {
    handleFileChange(uploadFile) {
      console.log(
        "%c [ uploadFile ] ==> 50 - Index.vue",
        "font-size:13px; background:pink; color:#bf2c9f;",
        uploadFile
      );
      if (uploadFile?.raw?.path) {
        this.pathStr = uploadFile?.raw?.path;
      }
    },
    test111() {
      console.log(
        "%c [ pathStr ] ==> 24 - Index.vue",
        "font-size:13px; background:pink; color:#bf2c9f;",
        this.pathStr
      );
      ipc.on("test", (...args) => {
        console.log(
          "%c [ args ] ==> 23 - Index.vue",
          "font-size:13px; background:pink; color:#bf2c9f;",
          args
        );
      });

      ipc
        .invoke("controller.example.test", {
          path: this.pathStr,
        })
        .then((r) => {
          // r为返回的数据
          console.log(r);
          this.tableData = r.data;
        });
    },
  },
};
</script>
<style scoped>
section {
  padding: 42px 32px;
}

#hero {
  padding: 150px 32px;
  text-align: center;
  height: 100%;
}

.tagline {
  font-size: 52px;
  line-height: 1.25;
  font-weight: bold;
  letter-spacing: -1.5px;
  max-width: 960px;
  margin: 0px auto;
}
html:not(.dark) .accent,
.dark .tagline {
  background: -webkit-linear-gradient(315deg, #42d392 25%, #647eff);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.description {
  max-width: 960px;
  line-height: 1.5;
  color: var(--vt-c-text-2);
  transition: color 0.5s;
  font-size: 22px;
  margin: 24px auto 40px;
}
.actions a {
  font-size: 16px;
  display: inline-block;
  background-color: var(--vt-c-bg-mute);
  padding: 8px 18px;
  font-weight: 500;
  border-radius: 8px;
  transition:
    background-color 0.5s,
    color 0.5s;
  text-decoration: none;
}
.actions .setup {
  color: var(--vt-c-text-code);
  background: -webkit-linear-gradient(315deg, #42d392 25%, #647eff);
}
.actions .setup:hover {
  background-color: var(--vt-c-gray-light-4);
  transition-duration: 0.2s;
}
</style>
